// pages/sureorder/sureorder.js
const app = getApp()
Page({

  data: {
    pid:'',
    list:'',
    numval:1,
    datainfo:'',
    color:'',
    xgimg: '',
  },

  onLoad: function (options) {
    console.log(options);
    this.setData({
      datainfo:options,
      xgimg: options.xgimg,
      pid: options.pid,
      color: options.color=='fff'?'0':'1'
    })
    this.getGoodsInfoList();
  },
  bindGetUserInfo(res){  //授权
    console.log(res);
    if (res.detail.userInfo) {
      console.log("点击了同意授权");
    } else {
      console.log("点击了拒绝授权");
    }
  },

  getGoodsInfoList() {
    let _that = this;
    wx.request({   //传后台
      url: app.globalData.url + '/jxb/goods/goods/getGoodsInfoList',
      method: 'GET',
      data: {},
      success: function (res) {
        _that.setData({
          list:res.data.data
        })
      },

    })
  },
  downnum(){ //数量减
    if (this.data.numval!==1){
     this.setData({
       numval: this.data.numval-1
     })
   }
  },
  addnum(){  //数量加
    this.setData({
      numval: this.data.numval+1
    })
  },
 
  sureorder(){  //确认下单
  let josn=this.data.list;
    let datainfo = this.data.datainfo;
   wx.navigateTo({
     url: '/pages/paymoney/paymoney?type=srdz&josn=' + JSON.stringify(josn) + '&numval=' + this.data.numval + '&datainfo=' + JSON.stringify(datainfo) + '&xgimg=' + this.data.xgimg + '&pid=' + this.data.pid ,
   }) 
  },
  addcar(){  //加入购物车
    let _that = this;
    wx.request({   //传后台
      url: app.globalData.url + '/jxb/goods/goods/addShopCart',
      method: 'GET',
      data: {
        pid: this.data.pid,
        gid: this.data.list[0].gid,
        token: wx.getStorageSync('token'),
        pidi:'',
        pidiurl: this.data.datainfo.xgimg,
        loan: this.data.datainfo.name,
        quotation: this.data.datainfo.talk,
        position: this.data.datainfo.location,
        num: this.data.numval,
        tcolor:this.data.color,
      },
      success: function (res) {
        wx.showToast({
          title: '已添加',
          icon: 'success',
          duration: 2000
        })
      },

    })
  },
})